//
//  FLLShopTableViewCell.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/9.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLShopTableViewCell.h"
#import "FLLMacro.h"
#import "FLLShopCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface FLLShopTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end
@implementation FLLShopTableViewCell

- (void)awakeFromNib {
    // Initialization code
    [self createShopCollectionView];
    
}
- (void)createShopCollectionView
{

    self.shopLayout.minimumInteritemSpacing = CellMargin;
    self.shopLayout.minimumLineSpacing = CellMargin;
    self.shopLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    self.shopCollectionView.dataSource = self;
    self.shopCollectionView.delegate = self;
    self.shopCollectionView.backgroundColor = FLLLightGrayColor;
    [self.shopCollectionView registerNib:[UINib nibWithNibName:@"FLLShopCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"shopCollectionCell"];
    
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return _collectionArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    FLLShopCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"shopCollectionCell" forIndexPath:indexPath];
    [cell.backgroundImage sd_setImageWithURL:[NSURL URLWithString:_collectionArray[indexPath.row].backgroundImage] placeholderImage:[UIImage new] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    
    cell.rightLabel.text = [NSString stringWithFormat:@"%@", _collectionArray[indexPath.row].promotionDesc];
    
    cell.rightLabel.font = [UIFont systemFontOfSize:11 * kWidthScale];
    cell.nameLabel.text = _collectionArray[indexPath.row].name;
    cell.nameLabel.font = [UIFont systemFontOfSize:13 * kWidthScale];
    cell.saleCountLabel.text = [NSString stringWithFormat:@"已售: %ld", (long)_collectionArray[indexPath.row].sales];
    cell.saleCountLabel.font = [UIFont systemFontOfSize:13 * kWidthScale];
    cell.postFreeLabel.font = [UIFont systemFontOfSize:13 * kWidthScale];
    cell.priceLabel.text = [NSString stringWithFormat:@"¥: %@", _collectionArray[indexPath.row].price];
    cell.priceLabel.font = [UIFont boldSystemFontOfSize:16 * kWidthScale];
    cell.streetPriceLabel.text = [NSString stringWithFormat:@"原价: %ld", (long)_collectionArray[indexPath.row].streetPrice];
    cell.streetPriceLabel.font = [UIFont systemFontOfSize:13 * kWidthScale];
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    CGFloat itemWidth = (_shopCollectionView.bounds.size.width - CellMargin) / 2.0 ;
    CGFloat itemHeight = 1.5 * itemWidth ;
    return CGSizeMake(itemWidth, itemHeight);
}
//- (void)setCollectionArray:(NSArray<ShopListcommodity *> *)collectionArray
//{
//
//    _collectionArray = collectionArray;
//    [self.shopCollectionView reloadData];
//}
- (void)setCollectionArray:(NSArray<ShopCollectionSecData *> *)collectionArray
{

    _collectionArray = collectionArray;
    [self.shopCollectionView reloadData];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
